#!/bin/bash

AUTH_MODULES=(maynrent-admin-auth maynrent-web-auth)
GATE_MODULES=(maynrent-admin-gate maynrent-web-gate)
SVC_MODULES=(maynrent-crm maynrent-finance maynrent-market maynrent-mc-service maynrent-order maynrent-sys maynrent-product maynrent-user maynrent-wms)
THIRD_MODULES=(maynrent-third maynrent-trade maynrent-report)
MIDDLE_MODULES=(maynrent-daemon)


echo "(1)开始发布鉴权模块......"

for moduleName in ${AUTH_MODULES[@]};do
	IMAGE_NAME=`cat $1/image_$moduleName`
	echo "更新镜像deployments/$moduleName-deployment $moduleName:${IMAGE_NAME}"
	kubectl set image deployments/$moduleName-deployment $moduleName=${IMAGE_NAME} --namespace=$2
	sleep 30s
	echo "更新$moduleName完毕"
done

echo "(2)开始发布网关模块......"
for moduleName in ${GATE_MODULES[@]};do
	IMAGE_NAME=`cat $1/image_$moduleName`
	echo "更新镜像deployments/$moduleName-deployment $moduleName:${IMAGE_NAME}"
	kubectl set image deployments/$moduleName-deployment $moduleName=${IMAGE_NAME} --namespace=$2
	sleep 30s
	echo "更新$moduleName完毕"
done

echo "(3)开始发布基础服务模块......"
for moduleName in ${SVC_MODULES[@]};do
IMAGE_NAME=`cat $1/image_$moduleName`
	echo "更新镜像deployments/$moduleName-deployment $moduleName:${IMAGE_NAME}"
	kubectl set image deployments/$moduleName-deployment $moduleName=${IMAGE_NAME} --namespace=$2
	sleep 30s
	echo "更新$moduleName完毕"
done

echo "(4)开始发布第三方服务模块......"
for moduleName in ${THIRD_MODULES[@]};do
	IMAGE_NAME=`cat $1/image_$moduleName`
	echo "更新镜像deployments/$moduleName-deployment $moduleName:${IMAGE_NAME}"
	kubectl set image deployments/$moduleName-deployment $moduleName=${IMAGE_NAME} --namespace=$2
	sleep 30s
	echo "更新$moduleName完毕"
done

echo "(5)开始发布中间件服务模块......"
for moduleName in ${MIDDLE_MODULES[@]};do
	IMAGE_NAME=`cat $1/image_$moduleName`
	echo "更新镜像deployments/$moduleName-deployment $moduleName:${IMAGE_NAME}"
	kubectl set image deployments/$moduleName-deployment $moduleName=${IMAGE_NAME} --namespace=$2
	sleep 30s
	echo "更新$moduleName完毕"
done

echo "所有系统模块更新完毕..."
